{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "\n",
    "pd.options.display.max_columns = 1000\n",
    "\n",
    "\n",
    "# Data: https://raw.githubusercontent.com/abulbasar/data/master/kaggle-houseprice/data_combined_cleaned.csv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "# https://github.com/abulbasar/machine-learning/blob/master/Scikit%20-%2020%20Kaggle%20House%20Data%20Preprocessing.ipynb"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.read_csv(\"/data/kaggle/data_combined_cleaned.csv\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Id</th>\n",
       "      <th>MSSubClass</th>\n",
       "      <th>MSZoning</th>\n",
       "      <th>LotFrontage</th>\n",
       "      <th>LotArea</th>\n",
       "      <th>Street</th>\n",
       "      <th>Alley</th>\n",
       "      <th>LotShape</th>\n",
       "      <th>LandContour</th>\n",
       "      <th>LotConfig</th>\n",
       "      <th>LandSlope</th>\n",
       "      <th>Neighborhood</th>\n",
       "      <th>Condition1</th>\n",
       "      <th>Condition2</th>\n",
       "      <th>BldgType</th>\n",
       "      <th>HouseStyle</th>\n",
       "      <th>OverallQual</th>\n",
       "      <th>OverallCond</th>\n",
       "      <th>YearBuilt</th>\n",
       "      <th>YearRemodAdd</th>\n",
       "      <th>RoofStyle</th>\n",
       "      <th>RoofMatl</th>\n",
       "      <th>Exterior1st</th>\n",
       "      <th>Exterior2nd</th>\n",
       "      <th>MasVnrType</th>\n",
       "      <th>MasVnrArea</th>\n",
       "      <th>ExterQual</th>\n",
       "      <th>ExterCond</th>\n",
       "      <th>Foundation</th>\n",
       "      <th>BsmtQual</th>\n",
       "      <th>BsmtCond</th>\n",
       "      <th>BsmtExposure</th>\n",
       "      <th>BsmtFinType1</th>\n",
       "      <th>BsmtFinSF1</th>\n",
       "      <th>BsmtFinType2</th>\n",
       "      <th>BsmtFinSF2</th>\n",
       "      <th>BsmtUnfSF</th>\n",
       "      <th>TotalBsmtSF</th>\n",
       "      <th>Heating</th>\n",
       "      <th>HeatingQC</th>\n",
       "      <th>CentralAir</th>\n",
       "      <th>Electrical</th>\n",
       "      <th>1stFlrSF</th>\n",
       "      <th>2ndFlrSF</th>\n",
       "      <th>LowQualFinSF</th>\n",
       "      <th>GrLivArea</th>\n",
       "      <th>BsmtFullBath</th>\n",
       "      <th>BsmtHalfBath</th>\n",
       "      <th>FullBath</th>\n",
       "      <th>HalfBath</th>\n",
       "      <th>BedroomAbvGr</th>\n",
       "      <th>KitchenAbvGr</th>\n",
       "      <th>KitchenQual</th>\n",
       "      <th>TotRmsAbvGrd</th>\n",
       "      <th>Functional</th>\n",
       "      <th>Fireplaces</th>\n",
       "      <th>FireplaceQu</th>\n",
       "      <th>GarageType</th>\n",
       "      <th>GarageYrBlt</th>\n",
       "      <th>GarageFinish</th>\n",
       "      <th>GarageCars</th>\n",
       "      <th>GarageArea</th>\n",
       "      <th>GarageQual</th>\n",
       "      <th>GarageCond</th>\n",
       "      <th>PavedDrive</th>\n",
       "      <th>WoodDeckSF</th>\n",
       "      <th>OpenPorchSF</th>\n",
       "      <th>EnclosedPorch</th>\n",
       "      <th>3SsnPorch</th>\n",
       "      <th>ScreenPorch</th>\n",
       "      <th>PoolArea</th>\n",
       "      <th>PoolQC</th>\n",
       "      <th>Fence</th>\n",
       "      <th>MiscFeature</th>\n",
       "      <th>MiscVal</th>\n",
       "      <th>MoSold</th>\n",
       "      <th>YrSold</th>\n",
       "      <th>SaleType</th>\n",
       "      <th>SaleCondition</th>\n",
       "      <th>SalesPrice</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>60</td>\n",
       "      <td>RL</td>\n",
       "      <td>65.0</td>\n",
       "      <td>8450</td>\n",
       "      <td>Pave</td>\n",
       "      <td>None</td>\n",
       "      <td>Reg</td>\n",
       "      <td>Lvl</td>\n",
       "      <td>Inside</td>\n",
       "      <td>Gtl</td>\n",
       "      <td>CollgCr</td>\n",
       "      <td>Norm</td>\n",
       "      <td>Norm</td>\n",
       "      <td>1Fam</td>\n",
       "      <td>2Story</td>\n",
       "      <td>7</td>\n",
       "      <td>5</td>\n",
       "      <td>2003</td>\n",
       "      <td>2003</td>\n",
       "      <td>Gable</td>\n",
       "      <td>CompShg</td>\n",
       "      <td>VinylSd</td>\n",
       "      <td>VinylSd</td>\n",
       "      <td>BrkFace</td>\n",
       "      <td>196.0</td>\n",
       "      <td>Gd</td>\n",
       "      <td>TA</td>\n",
       "      <td>PConc</td>\n",
       "      <td>Gd</td>\n",
       "      <td>TA</td>\n",
       "      <td>No</td>\n",
       "      <td>GLQ</td>\n",
       "      <td>706.0</td>\n",
       "      <td>Unf</td>\n",
       "      <td>0.0</td>\n",
       "      <td>150.0</td>\n",
       "      <td>856.0</td>\n",
       "      <td>GasA</td>\n",
       "      <td>Ex</td>\n",
       "      <td>Y</td>\n",
       "      <td>SBrkr</td>\n",
       "      <td>856</td>\n",
       "      <td>854</td>\n",
       "      <td>0</td>\n",
       "      <td>1710</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>Gd</td>\n",
       "      <td>8</td>\n",
       "      <td>Typ</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>Attchd</td>\n",
       "      <td>2003.0</td>\n",
       "      <td>RFn</td>\n",
       "      <td>2.0</td>\n",
       "      <td>548.0</td>\n",
       "      <td>TA</td>\n",
       "      <td>TA</td>\n",
       "      <td>Y</td>\n",
       "      <td>0</td>\n",
       "      <td>61</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>2008</td>\n",
       "      <td>WD</td>\n",
       "      <td>Normal</td>\n",
       "      <td>208500.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>20</td>\n",
       "      <td>RL</td>\n",
       "      <td>80.0</td>\n",
       "      <td>9600</td>\n",
       "      <td>Pave</td>\n",
       "      <td>None</td>\n",
       "      <td>Reg</td>\n",
       "      <td>Lvl</td>\n",
       "      <td>FR2</td>\n",
       "      <td>Gtl</td>\n",
       "      <td>Veenker</td>\n",
       "      <td>Feedr</td>\n",
       "      <td>Norm</td>\n",
       "      <td>1Fam</td>\n",
       "      <td>1Story</td>\n",
       "      <td>6</td>\n",
       "      <td>8</td>\n",
       "      <td>1976</td>\n",
       "      <td>1976</td>\n",
       "      <td>Gable</td>\n",
       "      <td>CompShg</td>\n",
       "      <td>MetalSd</td>\n",
       "      <td>MetalSd</td>\n",
       "      <td>None</td>\n",
       "      <td>0.0</td>\n",
       "      <td>TA</td>\n",
       "      <td>TA</td>\n",
       "      <td>CBlock</td>\n",
       "      <td>Gd</td>\n",
       "      <td>TA</td>\n",
       "      <td>Gd</td>\n",
       "      <td>ALQ</td>\n",
       "      <td>978.0</td>\n",
       "      <td>Unf</td>\n",
       "      <td>0.0</td>\n",
       "      <td>284.0</td>\n",
       "      <td>1262.0</td>\n",
       "      <td>GasA</td>\n",
       "      <td>Ex</td>\n",
       "      <td>Y</td>\n",
       "      <td>SBrkr</td>\n",
       "      <td>1262</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1262</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>TA</td>\n",
       "      <td>6</td>\n",
       "      <td>Typ</td>\n",
       "      <td>1</td>\n",
       "      <td>TA</td>\n",
       "      <td>Attchd</td>\n",
       "      <td>1976.0</td>\n",
       "      <td>RFn</td>\n",
       "      <td>2.0</td>\n",
       "      <td>460.0</td>\n",
       "      <td>TA</td>\n",
       "      <td>TA</td>\n",
       "      <td>Y</td>\n",
       "      <td>298</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "      <td>5</td>\n",
       "      <td>2007</td>\n",
       "      <td>WD</td>\n",
       "      <td>Normal</td>\n",
       "      <td>181500.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>60</td>\n",
       "      <td>RL</td>\n",
       "      <td>68.0</td>\n",
       "      <td>11250</td>\n",
       "      <td>Pave</td>\n",
       "      <td>None</td>\n",
       "      <td>IR1</td>\n",
       "      <td>Lvl</td>\n",
       "      <td>Inside</td>\n",
       "      <td>Gtl</td>\n",
       "      <td>CollgCr</td>\n",
       "      <td>Norm</td>\n",
       "      <td>Norm</td>\n",
       "      <td>1Fam</td>\n",
       "      <td>2Story</td>\n",
       "      <td>7</td>\n",
       "      <td>5</td>\n",
       "      <td>2001</td>\n",
       "      <td>2002</td>\n",
       "      <td>Gable</td>\n",
       "      <td>CompShg</td>\n",
       "      <td>VinylSd</td>\n",
       "      <td>VinylSd</td>\n",
       "      <td>BrkFace</td>\n",
       "      <td>162.0</td>\n",
       "      <td>Gd</td>\n",
       "      <td>TA</td>\n",
       "      <td>PConc</td>\n",
       "      <td>Gd</td>\n",
       "      <td>TA</td>\n",
       "      <td>Mn</td>\n",
       "      <td>GLQ</td>\n",
       "      <td>486.0</td>\n",
       "      <td>Unf</td>\n",
       "      <td>0.0</td>\n",
       "      <td>434.0</td>\n",
       "      <td>920.0</td>\n",
       "      <td>GasA</td>\n",
       "      <td>Ex</td>\n",
       "      <td>Y</td>\n",
       "      <td>SBrkr</td>\n",
       "      <td>920</td>\n",
       "      <td>866</td>\n",
       "      <td>0</td>\n",
       "      <td>1786</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>Gd</td>\n",
       "      <td>6</td>\n",
       "      <td>Typ</td>\n",
       "      <td>1</td>\n",
       "      <td>TA</td>\n",
       "      <td>Attchd</td>\n",
       "      <td>2001.0</td>\n",
       "      <td>RFn</td>\n",
       "      <td>2.0</td>\n",
       "      <td>608.0</td>\n",
       "      <td>TA</td>\n",
       "      <td>TA</td>\n",
       "      <td>Y</td>\n",
       "      <td>0</td>\n",
       "      <td>42</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>2008</td>\n",
       "      <td>WD</td>\n",
       "      <td>Normal</td>\n",
       "      <td>223500.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>70</td>\n",
       "      <td>RL</td>\n",
       "      <td>60.0</td>\n",
       "      <td>9550</td>\n",
       "      <td>Pave</td>\n",
       "      <td>None</td>\n",
       "      <td>IR1</td>\n",
       "      <td>Lvl</td>\n",
       "      <td>Corner</td>\n",
       "      <td>Gtl</td>\n",
       "      <td>Crawfor</td>\n",
       "      <td>Norm</td>\n",
       "      <td>Norm</td>\n",
       "      <td>1Fam</td>\n",
       "      <td>2Story</td>\n",
       "      <td>7</td>\n",
       "      <td>5</td>\n",
       "      <td>1915</td>\n",
       "      <td>1970</td>\n",
       "      <td>Gable</td>\n",
       "      <td>CompShg</td>\n",
       "      <td>Wd Sdng</td>\n",
       "      <td>Wd Shng</td>\n",
       "      <td>None</td>\n",
       "      <td>0.0</td>\n",
       "      <td>TA</td>\n",
       "      <td>TA</td>\n",
       "      <td>BrkTil</td>\n",
       "      <td>TA</td>\n",
       "      <td>Gd</td>\n",
       "      <td>No</td>\n",
       "      <td>ALQ</td>\n",
       "      <td>216.0</td>\n",
       "      <td>Unf</td>\n",
       "      <td>0.0</td>\n",
       "      <td>540.0</td>\n",
       "      <td>756.0</td>\n",
       "      <td>GasA</td>\n",
       "      <td>Gd</td>\n",
       "      <td>Y</td>\n",
       "      <td>SBrkr</td>\n",
       "      <td>961</td>\n",
       "      <td>756</td>\n",
       "      <td>0</td>\n",
       "      <td>1717</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>Gd</td>\n",
       "      <td>7</td>\n",
       "      <td>Typ</td>\n",
       "      <td>1</td>\n",
       "      <td>Gd</td>\n",
       "      <td>Detchd</td>\n",
       "      <td>1998.0</td>\n",
       "      <td>Unf</td>\n",
       "      <td>3.0</td>\n",
       "      <td>642.0</td>\n",
       "      <td>TA</td>\n",
       "      <td>TA</td>\n",
       "      <td>Y</td>\n",
       "      <td>0</td>\n",
       "      <td>35</td>\n",
       "      <td>272</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>2006</td>\n",
       "      <td>WD</td>\n",
       "      <td>Abnorml</td>\n",
       "      <td>140000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>60</td>\n",
       "      <td>RL</td>\n",
       "      <td>84.0</td>\n",
       "      <td>14260</td>\n",
       "      <td>Pave</td>\n",
       "      <td>None</td>\n",
       "      <td>IR1</td>\n",
       "      <td>Lvl</td>\n",
       "      <td>FR2</td>\n",
       "      <td>Gtl</td>\n",
       "      <td>NoRidge</td>\n",
       "      <td>Norm</td>\n",
       "      <td>Norm</td>\n",
       "      <td>1Fam</td>\n",
       "      <td>2Story</td>\n",
       "      <td>8</td>\n",
       "      <td>5</td>\n",
       "      <td>2000</td>\n",
       "      <td>2000</td>\n",
       "      <td>Gable</td>\n",
       "      <td>CompShg</td>\n",
       "      <td>VinylSd</td>\n",
       "      <td>VinylSd</td>\n",
       "      <td>BrkFace</td>\n",
       "      <td>350.0</td>\n",
       "      <td>Gd</td>\n",
       "      <td>TA</td>\n",
       "      <td>PConc</td>\n",
       "      <td>Gd</td>\n",
       "      <td>TA</td>\n",
       "      <td>Av</td>\n",
       "      <td>GLQ</td>\n",
       "      <td>655.0</td>\n",
       "      <td>Unf</td>\n",
       "      <td>0.0</td>\n",
       "      <td>490.0</td>\n",
       "      <td>1145.0</td>\n",
       "      <td>GasA</td>\n",
       "      <td>Ex</td>\n",
       "      <td>Y</td>\n",
       "      <td>SBrkr</td>\n",
       "      <td>1145</td>\n",
       "      <td>1053</td>\n",
       "      <td>0</td>\n",
       "      <td>2198</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>Gd</td>\n",
       "      <td>9</td>\n",
       "      <td>Typ</td>\n",
       "      <td>1</td>\n",
       "      <td>TA</td>\n",
       "      <td>Attchd</td>\n",
       "      <td>2000.0</td>\n",
       "      <td>RFn</td>\n",
       "      <td>3.0</td>\n",
       "      <td>836.0</td>\n",
       "      <td>TA</td>\n",
       "      <td>TA</td>\n",
       "      <td>Y</td>\n",
       "      <td>192</td>\n",
       "      <td>84</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "      <td>12</td>\n",
       "      <td>2008</td>\n",
       "      <td>WD</td>\n",
       "      <td>Normal</td>\n",
       "      <td>250000.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Id  MSSubClass MSZoning  LotFrontage  LotArea Street Alley LotShape  \\\n",
       "0   1          60       RL         65.0     8450   Pave  None      Reg   \n",
       "1   2          20       RL         80.0     9600   Pave  None      Reg   \n",
       "2   3          60       RL         68.0    11250   Pave  None      IR1   \n",
       "3   4          70       RL         60.0     9550   Pave  None      IR1   \n",
       "4   5          60       RL         84.0    14260   Pave  None      IR1   \n",
       "\n",
       "  LandContour LotConfig LandSlope Neighborhood Condition1 Condition2 BldgType  \\\n",
       "0         Lvl    Inside       Gtl      CollgCr       Norm       Norm     1Fam   \n",
       "1         Lvl       FR2       Gtl      Veenker      Feedr       Norm     1Fam   \n",
       "2         Lvl    Inside       Gtl      CollgCr       Norm       Norm     1Fam   \n",
       "3         Lvl    Corner       Gtl      Crawfor       Norm       Norm     1Fam   \n",
       "4         Lvl       FR2       Gtl      NoRidge       Norm       Norm     1Fam   \n",
       "\n",
       "  HouseStyle  OverallQual  OverallCond  YearBuilt  YearRemodAdd RoofStyle  \\\n",
       "0     2Story            7            5       2003          2003     Gable   \n",
       "1     1Story            6            8       1976          1976     Gable   \n",
       "2     2Story            7            5       2001          2002     Gable   \n",
       "3     2Story            7            5       1915          1970     Gable   \n",
       "4     2Story            8            5       2000          2000     Gable   \n",
       "\n",
       "  RoofMatl Exterior1st Exterior2nd MasVnrType  MasVnrArea ExterQual ExterCond  \\\n",
       "0  CompShg     VinylSd     VinylSd    BrkFace       196.0        Gd        TA   \n",
       "1  CompShg     MetalSd     MetalSd       None         0.0        TA        TA   \n",
       "2  CompShg     VinylSd     VinylSd    BrkFace       162.0        Gd        TA   \n",
       "3  CompShg     Wd Sdng     Wd Shng       None         0.0        TA        TA   \n",
       "4  CompShg     VinylSd     VinylSd    BrkFace       350.0        Gd        TA   \n",
       "\n",
       "  Foundation BsmtQual BsmtCond BsmtExposure BsmtFinType1  BsmtFinSF1  \\\n",
       "0      PConc       Gd       TA           No          GLQ       706.0   \n",
       "1     CBlock       Gd       TA           Gd          ALQ       978.0   \n",
       "2      PConc       Gd       TA           Mn          GLQ       486.0   \n",
       "3     BrkTil       TA       Gd           No          ALQ       216.0   \n",
       "4      PConc       Gd       TA           Av          GLQ       655.0   \n",
       "\n",
       "  BsmtFinType2  BsmtFinSF2  BsmtUnfSF  TotalBsmtSF Heating HeatingQC  \\\n",
       "0          Unf         0.0      150.0        856.0    GasA        Ex   \n",
       "1          Unf         0.0      284.0       1262.0    GasA        Ex   \n",
       "2          Unf         0.0      434.0        920.0    GasA        Ex   \n",
       "3          Unf         0.0      540.0        756.0    GasA        Gd   \n",
       "4          Unf         0.0      490.0       1145.0    GasA        Ex   \n",
       "\n",
       "  CentralAir Electrical  1stFlrSF  2ndFlrSF  LowQualFinSF  GrLivArea  \\\n",
       "0          Y      SBrkr       856       854             0       1710   \n",
       "1          Y      SBrkr      1262         0             0       1262   \n",
       "2          Y      SBrkr       920       866             0       1786   \n",
       "3          Y      SBrkr       961       756             0       1717   \n",
       "4          Y      SBrkr      1145      1053             0       2198   \n",
       "\n",
       "   BsmtFullBath  BsmtHalfBath  FullBath  HalfBath  BedroomAbvGr  KitchenAbvGr  \\\n",
       "0           1.0           0.0         2         1             3             1   \n",
       "1           0.0           1.0         2         0             3             1   \n",
       "2           1.0           0.0         2         1             3             1   \n",
       "3           1.0           0.0         1         0             3             1   \n",
       "4           1.0           0.0         2         1             4             1   \n",
       "\n",
       "  KitchenQual  TotRmsAbvGrd Functional  Fireplaces FireplaceQu GarageType  \\\n",
       "0          Gd             8        Typ           0        None     Attchd   \n",
       "1          TA             6        Typ           1          TA     Attchd   \n",
       "2          Gd             6        Typ           1          TA     Attchd   \n",
       "3          Gd             7        Typ           1          Gd     Detchd   \n",
       "4          Gd             9        Typ           1          TA     Attchd   \n",
       "\n",
       "   GarageYrBlt GarageFinish  GarageCars  GarageArea GarageQual GarageCond  \\\n",
       "0       2003.0          RFn         2.0       548.0         TA         TA   \n",
       "1       1976.0          RFn         2.0       460.0         TA         TA   \n",
       "2       2001.0          RFn         2.0       608.0         TA         TA   \n",
       "3       1998.0          Unf         3.0       642.0         TA         TA   \n",
       "4       2000.0          RFn         3.0       836.0         TA         TA   \n",
       "\n",
       "  PavedDrive  WoodDeckSF  OpenPorchSF  EnclosedPorch  3SsnPorch  ScreenPorch  \\\n",
       "0          Y           0           61              0          0            0   \n",
       "1          Y         298            0              0          0            0   \n",
       "2          Y           0           42              0          0            0   \n",
       "3          Y           0           35            272          0            0   \n",
       "4          Y         192           84              0          0            0   \n",
       "\n",
       "   PoolArea PoolQC Fence MiscFeature  MiscVal  MoSold  YrSold SaleType  \\\n",
       "0         0   None  None        None        0       2    2008       WD   \n",
       "1         0   None  None        None        0       5    2007       WD   \n",
       "2         0   None  None        None        0       9    2008       WD   \n",
       "3         0   None  None        None        0       2    2006       WD   \n",
       "4         0   None  None        None        0      12    2008       WD   \n",
       "\n",
       "  SaleCondition  SalesPrice  \n",
       "0        Normal    208500.0  \n",
       "1        Normal    181500.0  \n",
       "2        Normal    223500.0  \n",
       "3       Abnorml    140000.0  \n",
       "4        Normal    250000.0  "
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 2919 entries, 0 to 2918\n",
      "Data columns (total 80 columns):\n",
      " #   Column         Non-Null Count  Dtype  \n",
      "---  ------         --------------  -----  \n",
      " 0   Id             2919 non-null   int64  \n",
      " 1   MSSubClass     2919 non-null   int64  \n",
      " 2   MSZoning       2919 non-null   object \n",
      " 3   LotFrontage    2919 non-null   float64\n",
      " 4   LotArea        2919 non-null   int64  \n",
      " 5   Street         2919 non-null   object \n",
      " 6   Alley          2919 non-null   object \n",
      " 7   LotShape       2919 non-null   object \n",
      " 8   LandContour    2919 non-null   object \n",
      " 9   LotConfig      2919 non-null   object \n",
      " 10  LandSlope      2919 non-null   object \n",
      " 11  Neighborhood   2919 non-null   object \n",
      " 12  Condition1     2919 non-null   object \n",
      " 13  Condition2     2919 non-null   object \n",
      " 14  BldgType       2919 non-null   object \n",
      " 15  HouseStyle     2919 non-null   object \n",
      " 16  OverallQual    2919 non-null   int64  \n",
      " 17  OverallCond    2919 non-null   int64  \n",
      " 18  YearBuilt      2919 non-null   int64  \n",
      " 19  YearRemodAdd   2919 non-null   int64  \n",
      " 20  RoofStyle      2919 non-null   object \n",
      " 21  RoofMatl       2919 non-null   object \n",
      " 22  Exterior1st    2919 non-null   object \n",
      " 23  Exterior2nd    2919 non-null   object \n",
      " 24  MasVnrType     2919 non-null   object \n",
      " 25  MasVnrArea     2919 non-null   float64\n",
      " 26  ExterQual      2919 non-null   object \n",
      " 27  ExterCond      2919 non-null   object \n",
      " 28  Foundation     2919 non-null   object \n",
      " 29  BsmtQual       2919 non-null   object \n",
      " 30  BsmtCond       2919 non-null   object \n",
      " 31  BsmtExposure   2919 non-null   object \n",
      " 32  BsmtFinType1   2919 non-null   object \n",
      " 33  BsmtFinSF1     2919 non-null   float64\n",
      " 34  BsmtFinType2   2919 non-null   object \n",
      " 35  BsmtFinSF2     2919 non-null   float64\n",
      " 36  BsmtUnfSF      2919 non-null   float64\n",
      " 37  TotalBsmtSF    2919 non-null   float64\n",
      " 38  Heating        2919 non-null   object \n",
      " 39  HeatingQC      2919 non-null   object \n",
      " 40  CentralAir     2919 non-null   object \n",
      " 41  Electrical     2919 non-null   object \n",
      " 42  1stFlrSF       2919 non-null   int64  \n",
      " 43  2ndFlrSF       2919 non-null   int64  \n",
      " 44  LowQualFinSF   2919 non-null   int64  \n",
      " 45  GrLivArea      2919 non-null   int64  \n",
      " 46  BsmtFullBath   2919 non-null   float64\n",
      " 47  BsmtHalfBath   2919 non-null   float64\n",
      " 48  FullBath       2919 non-null   int64  \n",
      " 49  HalfBath       2919 non-null   int64  \n",
      " 50  BedroomAbvGr   2919 non-null   int64  \n",
      " 51  KitchenAbvGr   2919 non-null   int64  \n",
      " 52  KitchenQual    2919 non-null   object \n",
      " 53  TotRmsAbvGrd   2919 non-null   int64  \n",
      " 54  Functional     2919 non-null   object \n",
      " 55  Fireplaces     2919 non-null   int64  \n",
      " 56  FireplaceQu    2919 non-null   object \n",
      " 57  GarageType     2919 non-null   object \n",
      " 58  GarageYrBlt    2919 non-null   float64\n",
      " 59  GarageFinish   2919 non-null   object \n",
      " 60  GarageCars     2919 non-null   float64\n",
      " 61  GarageArea     2919 non-null   float64\n",
      " 62  GarageQual     2919 non-null   object \n",
      " 63  GarageCond     2919 non-null   object \n",
      " 64  PavedDrive     2919 non-null   object \n",
      " 65  WoodDeckSF     2919 non-null   int64  \n",
      " 66  OpenPorchSF    2919 non-null   int64  \n",
      " 67  EnclosedPorch  2919 non-null   int64  \n",
      " 68  3SsnPorch      2919 non-null   int64  \n",
      " 69  ScreenPorch    2919 non-null   int64  \n",
      " 70  PoolArea       2919 non-null   int64  \n",
      " 71  PoolQC         2919 non-null   object \n",
      " 72  Fence          2919 non-null   object \n",
      " 73  MiscFeature    2919 non-null   object \n",
      " 74  MiscVal        2919 non-null   int64  \n",
      " 75  MoSold         2919 non-null   int64  \n",
      " 76  YrSold         2919 non-null   int64  \n",
      " 77  SaleType       2919 non-null   object \n",
      " 78  SaleCondition  2919 non-null   object \n",
      " 79  SalesPrice     1460 non-null   float64\n",
      "dtypes: float64(12), int64(26), object(42)\n",
      "memory usage: 1.8+ MB\n"
     ]
    }
   ],
   "source": [
    "df.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "del df[\"Id\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = df[~df.SalesPrice.isna()]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "Int64Index: 1460 entries, 0 to 1459\n",
      "Data columns (total 79 columns):\n",
      " #   Column         Non-Null Count  Dtype  \n",
      "---  ------         --------------  -----  \n",
      " 0   MSSubClass     1460 non-null   int64  \n",
      " 1   MSZoning       1460 non-null   object \n",
      " 2   LotFrontage    1460 non-null   float64\n",
      " 3   LotArea        1460 non-null   int64  \n",
      " 4   Street         1460 non-null   object \n",
      " 5   Alley          1460 non-null   object \n",
      " 6   LotShape       1460 non-null   object \n",
      " 7   LandContour    1460 non-null   object \n",
      " 8   LotConfig      1460 non-null   object \n",
      " 9   LandSlope      1460 non-null   object \n",
      " 10  Neighborhood   1460 non-null   object \n",
      " 11  Condition1     1460 non-null   object \n",
      " 12  Condition2     1460 non-null   object \n",
      " 13  BldgType       1460 non-null   object \n",
      " 14  HouseStyle     1460 non-null   object \n",
      " 15  OverallQual    1460 non-null   int64  \n",
      " 16  OverallCond    1460 non-null   int64  \n",
      " 17  YearBuilt      1460 non-null   int64  \n",
      " 18  YearRemodAdd   1460 non-null   int64  \n",
      " 19  RoofStyle      1460 non-null   object \n",
      " 20  RoofMatl       1460 non-null   object \n",
      " 21  Exterior1st    1460 non-null   object \n",
      " 22  Exterior2nd    1460 non-null   object \n",
      " 23  MasVnrType     1460 non-null   object \n",
      " 24  MasVnrArea     1460 non-null   float64\n",
      " 25  ExterQual      1460 non-null   object \n",
      " 26  ExterCond      1460 non-null   object \n",
      " 27  Foundation     1460 non-null   object \n",
      " 28  BsmtQual       1460 non-null   object \n",
      " 29  BsmtCond       1460 non-null   object \n",
      " 30  BsmtExposure   1460 non-null   object \n",
      " 31  BsmtFinType1   1460 non-null   object \n",
      " 32  BsmtFinSF1     1460 non-null   float64\n",
      " 33  BsmtFinType2   1460 non-null   object \n",
      " 34  BsmtFinSF2     1460 non-null   float64\n",
      " 35  BsmtUnfSF      1460 non-null   float64\n",
      " 36  TotalBsmtSF    1460 non-null   float64\n",
      " 37  Heating        1460 non-null   object \n",
      " 38  HeatingQC      1460 non-null   object \n",
      " 39  CentralAir     1460 non-null   object \n",
      " 40  Electrical     1460 non-null   object \n",
      " 41  1stFlrSF       1460 non-null   int64  \n",
      " 42  2ndFlrSF       1460 non-null   int64  \n",
      " 43  LowQualFinSF   1460 non-null   int64  \n",
      " 44  GrLivArea      1460 non-null   int64  \n",
      " 45  BsmtFullBath   1460 non-null   float64\n",
      " 46  BsmtHalfBath   1460 non-null   float64\n",
      " 47  FullBath       1460 non-null   int64  \n",
      " 48  HalfBath       1460 non-null   int64  \n",
      " 49  BedroomAbvGr   1460 non-null   int64  \n",
      " 50  KitchenAbvGr   1460 non-null   int64  \n",
      " 51  KitchenQual    1460 non-null   object \n",
      " 52  TotRmsAbvGrd   1460 non-null   int64  \n",
      " 53  Functional     1460 non-null   object \n",
      " 54  Fireplaces     1460 non-null   int64  \n",
      " 55  FireplaceQu    1460 non-null   object \n",
      " 56  GarageType     1460 non-null   object \n",
      " 57  GarageYrBlt    1460 non-null   float64\n",
      " 58  GarageFinish   1460 non-null   object \n",
      " 59  GarageCars     1460 non-null   float64\n",
      " 60  GarageArea     1460 non-null   float64\n",
      " 61  GarageQual     1460 non-null   object \n",
      " 62  GarageCond     1460 non-null   object \n",
      " 63  PavedDrive     1460 non-null   object \n",
      " 64  WoodDeckSF     1460 non-null   int64  \n",
      " 65  OpenPorchSF    1460 non-null   int64  \n",
      " 66  EnclosedPorch  1460 non-null   int64  \n",
      " 67  3SsnPorch      1460 non-null   int64  \n",
      " 68  ScreenPorch    1460 non-null   int64  \n",
      " 69  PoolArea       1460 non-null   int64  \n",
      " 70  PoolQC         1460 non-null   object \n",
      " 71  Fence          1460 non-null   object \n",
      " 72  MiscFeature    1460 non-null   object \n",
      " 73  MiscVal        1460 non-null   int64  \n",
      " 74  MoSold         1460 non-null   int64  \n",
      " 75  YrSold         1460 non-null   int64  \n",
      " 76  SaleType       1460 non-null   object \n",
      " 77  SaleCondition  1460 non-null   object \n",
      " 78  SalesPrice     1460 non-null   float64\n",
      "dtypes: float64(12), int64(25), object(42)\n",
      "memory usage: 912.5+ KB\n"
     ]
    }
   ],
   "source": [
    "df.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>MSSubClass</th>\n",
       "      <th>MSZoning</th>\n",
       "      <th>LotFrontage</th>\n",
       "      <th>LotArea</th>\n",
       "      <th>Street</th>\n",
       "      <th>Alley</th>\n",
       "      <th>LotShape</th>\n",
       "      <th>LandContour</th>\n",
       "      <th>LotConfig</th>\n",
       "      <th>LandSlope</th>\n",
       "      <th>Neighborhood</th>\n",
       "      <th>Condition1</th>\n",
       "      <th>Condition2</th>\n",
       "      <th>BldgType</th>\n",
       "      <th>HouseStyle</th>\n",
       "      <th>OverallQual</th>\n",
       "      <th>OverallCond</th>\n",
       "      <th>YearBuilt</th>\n",
       "      <th>YearRemodAdd</th>\n",
       "      <th>RoofStyle</th>\n",
       "      <th>RoofMatl</th>\n",
       "      <th>Exterior1st</th>\n",
       "      <th>Exterior2nd</th>\n",
       "      <th>MasVnrType</th>\n",
       "      <th>MasVnrArea</th>\n",
       "      <th>ExterQual</th>\n",
       "      <th>ExterCond</th>\n",
       "      <th>Foundation</th>\n",
       "      <th>BsmtQual</th>\n",
       "      <th>BsmtCond</th>\n",
       "      <th>BsmtExposure</th>\n",
       "      <th>BsmtFinType1</th>\n",
       "      <th>BsmtFinSF1</th>\n",
       "      <th>BsmtFinType2</th>\n",
       "      <th>BsmtFinSF2</th>\n",
       "      <th>BsmtUnfSF</th>\n",
       "      <th>TotalBsmtSF</th>\n",
       "      <th>Heating</th>\n",
       "      <th>HeatingQC</th>\n",
       "      <th>CentralAir</th>\n",
       "      <th>Electrical</th>\n",
       "      <th>1stFlrSF</th>\n",
       "      <th>2ndFlrSF</th>\n",
       "      <th>LowQualFinSF</th>\n",
       "      <th>GrLivArea</th>\n",
       "      <th>BsmtFullBath</th>\n",
       "      <th>BsmtHalfBath</th>\n",
       "      <th>FullBath</th>\n",
       "      <th>HalfBath</th>\n",
       "      <th>BedroomAbvGr</th>\n",
       "      <th>KitchenAbvGr</th>\n",
       "      <th>KitchenQual</th>\n",
       "      <th>TotRmsAbvGrd</th>\n",
       "      <th>Functional</th>\n",
       "      <th>Fireplaces</th>\n",
       "      <th>FireplaceQu</th>\n",
       "      <th>GarageType</th>\n",
       "      <th>GarageYrBlt</th>\n",
       "      <th>GarageFinish</th>\n",
       "      <th>GarageCars</th>\n",
       "      <th>GarageArea</th>\n",
       "      <th>GarageQual</th>\n",
       "      <th>GarageCond</th>\n",
       "      <th>PavedDrive</th>\n",
       "      <th>WoodDeckSF</th>\n",
       "      <th>OpenPorchSF</th>\n",
       "      <th>EnclosedPorch</th>\n",
       "      <th>3SsnPorch</th>\n",
       "      <th>ScreenPorch</th>\n",
       "      <th>PoolArea</th>\n",
       "      <th>PoolQC</th>\n",
       "      <th>Fence</th>\n",
       "      <th>MiscFeature</th>\n",
       "      <th>MiscVal</th>\n",
       "      <th>MoSold</th>\n",
       "      <th>YrSold</th>\n",
       "      <th>SaleType</th>\n",
       "      <th>SaleCondition</th>\n",
       "      <th>SalesPrice</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>60</td>\n",
       "      <td>RL</td>\n",
       "      <td>65.0</td>\n",
       "      <td>8450</td>\n",
       "      <td>Pave</td>\n",
       "      <td>None</td>\n",
       "      <td>Reg</td>\n",
       "      <td>Lvl</td>\n",
       "      <td>Inside</td>\n",
       "      <td>Gtl</td>\n",
       "      <td>CollgCr</td>\n",
       "      <td>Norm</td>\n",
       "      <td>Norm</td>\n",
       "      <td>1Fam</td>\n",
       "      <td>2Story</td>\n",
       "      <td>7</td>\n",
       "      <td>5</td>\n",
       "      <td>2003</td>\n",
       "      <td>2003</td>\n",
       "      <td>Gable</td>\n",
       "      <td>CompShg</td>\n",
       "      <td>VinylSd</td>\n",
       "      <td>VinylSd</td>\n",
       "      <td>BrkFace</td>\n",
       "      <td>196.0</td>\n",
       "      <td>Gd</td>\n",
       "      <td>TA</td>\n",
       "      <td>PConc</td>\n",
       "      <td>Gd</td>\n",
       "      <td>TA</td>\n",
       "      <td>No</td>\n",
       "      <td>GLQ</td>\n",
       "      <td>706.0</td>\n",
       "      <td>Unf</td>\n",
       "      <td>0.0</td>\n",
       "      <td>150.0</td>\n",
       "      <td>856.0</td>\n",
       "      <td>GasA</td>\n",
       "      <td>Ex</td>\n",
       "      <td>Y</td>\n",
       "      <td>SBrkr</td>\n",
       "      <td>856</td>\n",
       "      <td>854</td>\n",
       "      <td>0</td>\n",
       "      <td>1710</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>Gd</td>\n",
       "      <td>8</td>\n",
       "      <td>Typ</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>Attchd</td>\n",
       "      <td>2003.0</td>\n",
       "      <td>RFn</td>\n",
       "      <td>2.0</td>\n",
       "      <td>548.0</td>\n",
       "      <td>TA</td>\n",
       "      <td>TA</td>\n",
       "      <td>Y</td>\n",
       "      <td>0</td>\n",
       "      <td>61</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>2008</td>\n",
       "      <td>WD</td>\n",
       "      <td>Normal</td>\n",
       "      <td>208500.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>20</td>\n",
       "      <td>RL</td>\n",
       "      <td>80.0</td>\n",
       "      <td>9600</td>\n",
       "      <td>Pave</td>\n",
       "      <td>None</td>\n",
       "      <td>Reg</td>\n",
       "      <td>Lvl</td>\n",
       "      <td>FR2</td>\n",
       "      <td>Gtl</td>\n",
       "      <td>Veenker</td>\n",
       "      <td>Feedr</td>\n",
       "      <td>Norm</td>\n",
       "      <td>1Fam</td>\n",
       "      <td>1Story</td>\n",
       "      <td>6</td>\n",
       "      <td>8</td>\n",
       "      <td>1976</td>\n",
       "      <td>1976</td>\n",
       "      <td>Gable</td>\n",
       "      <td>CompShg</td>\n",
       "      <td>MetalSd</td>\n",
       "      <td>MetalSd</td>\n",
       "      <td>None</td>\n",
       "      <td>0.0</td>\n",
       "      <td>TA</td>\n",
       "      <td>TA</td>\n",
       "      <td>CBlock</td>\n",
       "      <td>Gd</td>\n",
       "      <td>TA</td>\n",
       "      <td>Gd</td>\n",
       "      <td>ALQ</td>\n",
       "      <td>978.0</td>\n",
       "      <td>Unf</td>\n",
       "      <td>0.0</td>\n",
       "      <td>284.0</td>\n",
       "      <td>1262.0</td>\n",
       "      <td>GasA</td>\n",
       "      <td>Ex</td>\n",
       "      <td>Y</td>\n",
       "      <td>SBrkr</td>\n",
       "      <td>1262</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1262</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>TA</td>\n",
       "      <td>6</td>\n",
       "      <td>Typ</td>\n",
       "      <td>1</td>\n",
       "      <td>TA</td>\n",
       "      <td>Attchd</td>\n",
       "      <td>1976.0</td>\n",
       "      <td>RFn</td>\n",
       "      <td>2.0</td>\n",
       "      <td>460.0</td>\n",
       "      <td>TA</td>\n",
       "      <td>TA</td>\n",
       "      <td>Y</td>\n",
       "      <td>298</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "      <td>5</td>\n",
       "      <td>2007</td>\n",
       "      <td>WD</td>\n",
       "      <td>Normal</td>\n",
       "      <td>181500.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>60</td>\n",
       "      <td>RL</td>\n",
       "      <td>68.0</td>\n",
       "      <td>11250</td>\n",
       "      <td>Pave</td>\n",
       "      <td>None</td>\n",
       "      <td>IR1</td>\n",
       "      <td>Lvl</td>\n",
       "      <td>Inside</td>\n",
       "      <td>Gtl</td>\n",
       "      <td>CollgCr</td>\n",
       "      <td>Norm</td>\n",
       "      <td>Norm</td>\n",
       "      <td>1Fam</td>\n",
       "      <td>2Story</td>\n",
       "      <td>7</td>\n",
       "      <td>5</td>\n",
       "      <td>2001</td>\n",
       "      <td>2002</td>\n",
       "      <td>Gable</td>\n",
       "      <td>CompShg</td>\n",
       "      <td>VinylSd</td>\n",
       "      <td>VinylSd</td>\n",
       "      <td>BrkFace</td>\n",
       "      <td>162.0</td>\n",
       "      <td>Gd</td>\n",
       "      <td>TA</td>\n",
       "      <td>PConc</td>\n",
       "      <td>Gd</td>\n",
       "      <td>TA</td>\n",
       "      <td>Mn</td>\n",
       "      <td>GLQ</td>\n",
       "      <td>486.0</td>\n",
       "      <td>Unf</td>\n",
       "      <td>0.0</td>\n",
       "      <td>434.0</td>\n",
       "      <td>920.0</td>\n",
       "      <td>GasA</td>\n",
       "      <td>Ex</td>\n",
       "      <td>Y</td>\n",
       "      <td>SBrkr</td>\n",
       "      <td>920</td>\n",
       "      <td>866</td>\n",
       "      <td>0</td>\n",
       "      <td>1786</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>Gd</td>\n",
       "      <td>6</td>\n",
       "      <td>Typ</td>\n",
       "      <td>1</td>\n",
       "      <td>TA</td>\n",
       "      <td>Attchd</td>\n",
       "      <td>2001.0</td>\n",
       "      <td>RFn</td>\n",
       "      <td>2.0</td>\n",
       "      <td>608.0</td>\n",
       "      <td>TA</td>\n",
       "      <td>TA</td>\n",
       "      <td>Y</td>\n",
       "      <td>0</td>\n",
       "      <td>42</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>2008</td>\n",
       "      <td>WD</td>\n",
       "      <td>Normal</td>\n",
       "      <td>223500.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>70</td>\n",
       "      <td>RL</td>\n",
       "      <td>60.0</td>\n",
       "      <td>9550</td>\n",
       "      <td>Pave</td>\n",
       "      <td>None</td>\n",
       "      <td>IR1</td>\n",
       "      <td>Lvl</td>\n",
       "      <td>Corner</td>\n",
       "      <td>Gtl</td>\n",
       "      <td>Crawfor</td>\n",
       "      <td>Norm</td>\n",
       "      <td>Norm</td>\n",
       "      <td>1Fam</td>\n",
       "      <td>2Story</td>\n",
       "      <td>7</td>\n",
       "      <td>5</td>\n",
       "      <td>1915</td>\n",
       "      <td>1970</td>\n",
       "      <td>Gable</td>\n",
       "      <td>CompShg</td>\n",
       "      <td>Wd Sdng</td>\n",
       "      <td>Wd Shng</td>\n",
       "      <td>None</td>\n",
       "      <td>0.0</td>\n",
       "      <td>TA</td>\n",
       "      <td>TA</td>\n",
       "      <td>BrkTil</td>\n",
       "      <td>TA</td>\n",
       "      <td>Gd</td>\n",
       "      <td>No</td>\n",
       "      <td>ALQ</td>\n",
       "      <td>216.0</td>\n",
       "      <td>Unf</td>\n",
       "      <td>0.0</td>\n",
       "      <td>540.0</td>\n",
       "      <td>756.0</td>\n",
       "      <td>GasA</td>\n",
       "      <td>Gd</td>\n",
       "      <td>Y</td>\n",
       "      <td>SBrkr</td>\n",
       "      <td>961</td>\n",
       "      <td>756</td>\n",
       "      <td>0</td>\n",
       "      <td>1717</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>Gd</td>\n",
       "      <td>7</td>\n",
       "      <td>Typ</td>\n",
       "      <td>1</td>\n",
       "      <td>Gd</td>\n",
       "      <td>Detchd</td>\n",
       "      <td>1998.0</td>\n",
       "      <td>Unf</td>\n",
       "      <td>3.0</td>\n",
       "      <td>642.0</td>\n",
       "      <td>TA</td>\n",
       "      <td>TA</td>\n",
       "      <td>Y</td>\n",
       "      <td>0</td>\n",
       "      <td>35</td>\n",
       "      <td>272</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>2006</td>\n",
       "      <td>WD</td>\n",
       "      <td>Abnorml</td>\n",
       "      <td>140000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>60</td>\n",
       "      <td>RL</td>\n",
       "      <td>84.0</td>\n",
       "      <td>14260</td>\n",
       "      <td>Pave</td>\n",
       "      <td>None</td>\n",
       "      <td>IR1</td>\n",
       "      <td>Lvl</td>\n",
       "      <td>FR2</td>\n",
       "      <td>Gtl</td>\n",
       "      <td>NoRidge</td>\n",
       "      <td>Norm</td>\n",
       "      <td>Norm</td>\n",
       "      <td>1Fam</td>\n",
       "      <td>2Story</td>\n",
       "      <td>8</td>\n",
       "      <td>5</td>\n",
       "      <td>2000</td>\n",
       "      <td>2000</td>\n",
       "      <td>Gable</td>\n",
       "      <td>CompShg</td>\n",
       "      <td>VinylSd</td>\n",
       "      <td>VinylSd</td>\n",
       "      <td>BrkFace</td>\n",
       "      <td>350.0</td>\n",
       "      <td>Gd</td>\n",
       "      <td>TA</td>\n",
       "      <td>PConc</td>\n",
       "      <td>Gd</td>\n",
       "      <td>TA</td>\n",
       "      <td>Av</td>\n",
       "      <td>GLQ</td>\n",
       "      <td>655.0</td>\n",
       "      <td>Unf</td>\n",
       "      <td>0.0</td>\n",
       "      <td>490.0</td>\n",
       "      <td>1145.0</td>\n",
       "      <td>GasA</td>\n",
       "      <td>Ex</td>\n",
       "      <td>Y</td>\n",
       "      <td>SBrkr</td>\n",
       "      <td>1145</td>\n",
       "      <td>1053</td>\n",
       "      <td>0</td>\n",
       "      <td>2198</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>Gd</td>\n",
       "      <td>9</td>\n",
       "      <td>Typ</td>\n",
       "      <td>1</td>\n",
       "      <td>TA</td>\n",
       "      <td>Attchd</td>\n",
       "      <td>2000.0</td>\n",
       "      <td>RFn</td>\n",
       "      <td>3.0</td>\n",
       "      <td>836.0</td>\n",
       "      <td>TA</td>\n",
       "      <td>TA</td>\n",
       "      <td>Y</td>\n",
       "      <td>192</td>\n",
       "      <td>84</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "      <td>12</td>\n",
       "      <td>2008</td>\n",
       "      <td>WD</td>\n",
       "      <td>Normal</td>\n",
       "      <td>250000.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   MSSubClass MSZoning  LotFrontage  LotArea Street Alley LotShape  \\\n",
       "0          60       RL         65.0     8450   Pave  None      Reg   \n",
       "1          20       RL         80.0     9600   Pave  None      Reg   \n",
       "2          60       RL         68.0    11250   Pave  None      IR1   \n",
       "3          70       RL         60.0     9550   Pave  None      IR1   \n",
       "4          60       RL         84.0    14260   Pave  None      IR1   \n",
       "\n",
       "  LandContour LotConfig LandSlope Neighborhood Condition1 Condition2 BldgType  \\\n",
       "0         Lvl    Inside       Gtl      CollgCr       Norm       Norm     1Fam   \n",
       "1         Lvl       FR2       Gtl      Veenker      Feedr       Norm     1Fam   \n",
       "2         Lvl    Inside       Gtl      CollgCr       Norm       Norm     1Fam   \n",
       "3         Lvl    Corner       Gtl      Crawfor       Norm       Norm     1Fam   \n",
       "4         Lvl       FR2       Gtl      NoRidge       Norm       Norm     1Fam   \n",
       "\n",
       "  HouseStyle  OverallQual  OverallCond  YearBuilt  YearRemodAdd RoofStyle  \\\n",
       "0     2Story            7            5       2003          2003     Gable   \n",
       "1     1Story            6            8       1976          1976     Gable   \n",
       "2     2Story            7            5       2001          2002     Gable   \n",
       "3     2Story            7            5       1915          1970     Gable   \n",
       "4     2Story            8            5       2000          2000     Gable   \n",
       "\n",
       "  RoofMatl Exterior1st Exterior2nd MasVnrType  MasVnrArea ExterQual ExterCond  \\\n",
       "0  CompShg     VinylSd     VinylSd    BrkFace       196.0        Gd        TA   \n",
       "1  CompShg     MetalSd     MetalSd       None         0.0        TA        TA   \n",
       "2  CompShg     VinylSd     VinylSd    BrkFace       162.0        Gd        TA   \n",
       "3  CompShg     Wd Sdng     Wd Shng       None         0.0        TA        TA   \n",
       "4  CompShg     VinylSd     VinylSd    BrkFace       350.0        Gd        TA   \n",
       "\n",
       "  Foundation BsmtQual BsmtCond BsmtExposure BsmtFinType1  BsmtFinSF1  \\\n",
       "0      PConc       Gd       TA           No          GLQ       706.0   \n",
       "1     CBlock       Gd       TA           Gd          ALQ       978.0   \n",
       "2      PConc       Gd       TA           Mn          GLQ       486.0   \n",
       "3     BrkTil       TA       Gd           No          ALQ       216.0   \n",
       "4      PConc       Gd       TA           Av          GLQ       655.0   \n",
       "\n",
       "  BsmtFinType2  BsmtFinSF2  BsmtUnfSF  TotalBsmtSF Heating HeatingQC  \\\n",
       "0          Unf         0.0      150.0        856.0    GasA        Ex   \n",
       "1          Unf         0.0      284.0       1262.0    GasA        Ex   \n",
       "2          Unf         0.0      434.0        920.0    GasA        Ex   \n",
       "3          Unf         0.0      540.0        756.0    GasA        Gd   \n",
       "4          Unf         0.0      490.0       1145.0    GasA        Ex   \n",
       "\n",
       "  CentralAir Electrical  1stFlrSF  2ndFlrSF  LowQualFinSF  GrLivArea  \\\n",
       "0          Y      SBrkr       856       854             0       1710   \n",
       "1          Y      SBrkr      1262         0             0       1262   \n",
       "2          Y      SBrkr       920       866             0       1786   \n",
       "3          Y      SBrkr       961       756             0       1717   \n",
       "4          Y      SBrkr      1145      1053             0       2198   \n",
       "\n",
       "   BsmtFullBath  BsmtHalfBath  FullBath  HalfBath  BedroomAbvGr  KitchenAbvGr  \\\n",
       "0           1.0           0.0         2         1             3             1   \n",
       "1           0.0           1.0         2         0             3             1   \n",
       "2           1.0           0.0         2         1             3             1   \n",
       "3           1.0           0.0         1         0             3             1   \n",
       "4           1.0           0.0         2         1             4             1   \n",
       "\n",
       "  KitchenQual  TotRmsAbvGrd Functional  Fireplaces FireplaceQu GarageType  \\\n",
       "0          Gd             8        Typ           0        None     Attchd   \n",
       "1          TA             6        Typ           1          TA     Attchd   \n",
       "2          Gd             6        Typ           1          TA     Attchd   \n",
       "3          Gd             7        Typ           1          Gd     Detchd   \n",
       "4          Gd             9        Typ           1          TA     Attchd   \n",
       "\n",
       "   GarageYrBlt GarageFinish  GarageCars  GarageArea GarageQual GarageCond  \\\n",
       "0       2003.0          RFn         2.0       548.0         TA         TA   \n",
       "1       1976.0          RFn         2.0       460.0         TA         TA   \n",
       "2       2001.0          RFn         2.0       608.0         TA         TA   \n",
       "3       1998.0          Unf         3.0       642.0         TA         TA   \n",
       "4       2000.0          RFn         3.0       836.0         TA         TA   \n",
       "\n",
       "  PavedDrive  WoodDeckSF  OpenPorchSF  EnclosedPorch  3SsnPorch  ScreenPorch  \\\n",
       "0          Y           0           61              0          0            0   \n",
       "1          Y         298            0              0          0            0   \n",
       "2          Y           0           42              0          0            0   \n",
       "3          Y           0           35            272          0            0   \n",
       "4          Y         192           84              0          0            0   \n",
       "\n",
       "   PoolArea PoolQC Fence MiscFeature  MiscVal  MoSold  YrSold SaleType  \\\n",
       "0         0   None  None        None        0       2    2008       WD   \n",
       "1         0   None  None        None        0       5    2007       WD   \n",
       "2         0   None  None        None        0       9    2008       WD   \n",
       "3         0   None  None        None        0       2    2006       WD   \n",
       "4         0   None  None        None        0      12    2008       WD   \n",
       "\n",
       "  SaleCondition  SalesPrice  \n",
       "0        Normal    208500.0  \n",
       "1        Normal    181500.0  \n",
       "2        Normal    223500.0  \n",
       "3       Abnorml    140000.0  \n",
       "4        Normal    250000.0  "
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_dummy = pd.get_dummies(df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [],
   "source": [
    "target = \"SalesPrice\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [],
   "source": [
    "y = np.log(df[target])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [],
   "source": [
    "X = df_dummy.drop(columns=target)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.axes._subplots.AxesSubplot at 0x11952f990>"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAAD4CAYAAAAD6PrjAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjMsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+AADFEAAATbklEQVR4nO3dcdBldX3f8fdHCKJWCriLJbtsHnR2iJZJRvqEOqG1NsQURQGbkGKcZge32XZCYlLbCatkJDMdZ5YmDeqkjV2FulqDosawqVpciYbpTEEfFAVEwwa3sC5hnxSRGKxk8ds/7tmT63rvPneffc6993nu+zXzzD3nd8+99/ubw94Pv3N+59xUFZIkATxj0gVIkqaHoSBJahkKkqSWoSBJahkKkqTWiZMu4HisW7eu5ubmJl2GJK0qd911119W1fpBz63qUJibm2NhYWHSZUjSqpLk/wx7zsN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PwPZmeTtw3ZDXfnvS9S/RjxcB5wCfBeaHvO4E4M+BFwAnAV8CXrya+tBstw9YN+n9cJR+/AxwYrN83aD/plbBvliyD6tkX5zSt/xG4F0DXnc68GDzeFqzfNpq6kPz3Ip/R635kUJV3Q48dkTzpcCuZnkXcNlYi1qGQf2oqvuraqkruqfm1iHH0YepMqQfn6qqQ83qHfSusTnStO+LUfowVYb044m+1edwxAWwjX8G7Kmqx6rqm8Ae4KLOCj2K4+hDJ9Z8KAzx/Kp6BKB5PGPIdicnWUhyR5KpD44hBt06ZMOEajkeBXwqyV3NrU6m2RuATw5oX037YlgfYBXsiyRvS/Iw8HrgrQM2mfp9MUIfoIPvqFkNhVFtqt5l5b8AvD3JCydd0DIseeuQVeKCqjoPeCVwVZKXTbqgQZJcAxwCPjDo6QFtU7cvlugDrIJ9UVXXVNVZ9PrwKwM2mfp9MUIfoIPvqFkNhUeTnAnQPB4ctFFVHWgeH6R3zPsl4ypwBa2JW4f07YuDwMfoHYqZKs3JylcDr6/mgO8Rpn5fjNCHVbEv+vwB8LMD2qd+X/QZ1odOvqNmNRR2A4dnG2wBbjlygySnJXlms7wOuABYjb/rsOpvHZLkOUmee3iZ3gnRe4/+qvFK78ehrgYuqaonh2w21ftilD6skn2xuW/1EuCrAza7FfiZ5t/5afT6ces46hvFKH3o7DtqEmfbx/kH3AQ8AvwNvf872Ao8D7gNeKB5PL3Zdp7er70B/CRwD70ZIvcAW6ewH69tlr8LPArc2mz7w8An+l77KuDP6M18uWa19YHebJ0vNX/3TbIPR+nHXnrHqO9u/t61CvfFkn1YJfvio/SC6svAHwMbmm3bf9/N+huaPu8FrlxtfejqO8rbXEiSWrN6+EiSNIChIElqGQqSpJahIElqGQqSpJahIElqGQqSpNb/B8TNsClNClJaAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "y.plot.hist(bins = 35)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.axes._subplots.AxesSubplot at 0x1a25237a10>"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAAD4CAYAAAAD6PrjAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjMsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+AADFEAAASRUlEQVR4nO3de5BkZXnH8e/jckcUcBeyAjqQ2hBJSmEdEQtjoXjhEkErYqAspQi6qQgVKVMVF0yp+cOqTUqNUqaQVYmLURBUZCMaXNZbJRWBAZGLgCy6gXFXdtEIRIwIPvnjvPNus/TM9Cx9unt2vp+qrj7n7XN5Zrqnf3Pec4vMRJIkgGcMuwBJ0ugwFCRJlaEgSaoMBUlSZShIkqpdhl3A07F48eIcGxsbdhmSNK/cdNNND2bmkm6vzetQGBsbY2JiYthlSNK8EhH/Pd1rdh9JkipDQZJUGQqSpMpQkCRVhoIkqTIUJEmVoSBJqgwFSVJlKEiSqnl9RvPOYmzlNbNOs3HVyQOoRNJC55aCJKkyFCRJlaEgSarcpzBPuN9B0iC4pSBJqgwFSVJlKEiSKkNBklQZCpKkylCQJFWGgiSpMhQkSZWhIEmqDAVJUmUoSJIqQ0GSVBkKkqTKUJAkVYaCJKkyFCRJlaEgSaoMBUlSZShIkipDQZJUtRYKEXFIRHwrIu6MiDsi4l2lff+IWBcR95Tn/Up7RMSFEbEhIm6NiOVt1SZJ6q7NLYXHgb/JzBcAxwDnRMQRwEpgfWYuA9aXcYATgWXlsQK4qMXaJEldtBYKmbk5M28uw48AdwIHAacCa8pka4A3lOFTgUuz8T1g34hY2lZ9kqSnGsg+hYgYA44CrgcOzMzN0AQ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faT+M5styA82m+u6lfY8yvqG8fljHst5barmbcuTGTJ+N6dbRw2fgOLYdfTRydZbpf8C2w3zfO9P7Mqz3vkx/JDBR3v+v0ByRM3J1lnn2ork0/7M72kay1n4+vMyFJKmar91HkqQWGAqSpMpQkCRVhoIkqTIUJEmVoSBJqgwFSVL1/8/61iuiBx+BAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "df[target].plot.hist(bins = 35)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn import * "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [],
   "source": [
    "X_train, X_test, y_train, y_test = model_selection.train_test_split(X, y, test_size = 0.3, random_state = 1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 98,
   "metadata": {},
   "outputs": [],
   "source": [
    "scaler = preprocessing.StandardScaler()\n",
    "X_train_std = scaler.fit_transform(X_train)\n",
    "X_test_std = scaler.transform(X_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 99,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Lasso(alpha=0.05, copy_X=True, fit_intercept=True, max_iter=1000,\n",
       "      normalize=False, positive=False, precompute=False, random_state=1,\n",
       "      selection='cyclic', tol=0.0001, warm_start=False)"
      ]
     },
     "execution_count": 99,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lr = linear_model.Lasso(alpha=0.05, random_state=1)\n",
    "lr.fit(X_train_std, y_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 100,
   "metadata": {},
   "outputs": [],
   "source": [
    "y_train_pred = lr.predict(X_train_std)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 101,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.17846084266441412"
      ]
     },
     "execution_count": 101,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rmse = metrics.mean_squared_error(y_train, y_train_pred) ** 0.5\n",
    "rmse"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 102,
   "metadata": {},
   "outputs": [],
   "source": [
    "y_test_pred = lr.predict(X_test_std)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 103,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.198150257844202"
      ]
     },
     "execution_count": 103,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rmse = metrics.mean_squared_error(y_test, y_test_pred) ** 0.5\n",
    "rmse"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(0.7826767930566376, 0.7922449325754148)"
      ]
     },
     "execution_count": 92,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "metrics.r2_score(y_train, y_train_pred), metrics.r2_score(y_test, y_test_pred)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 104,
   "metadata": {},
   "outputs": [],
   "source": [
    "y_train_error = y_train - y_train_pred"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 105,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Lasso(alpha=0.05, copy_X=True, fit_intercept=True, max_iter=1000,\n",
       "      normalize=False, positive=False, precompute=False, random_state=1,\n",
       "      selection='cyclic', tol=0.0001, warm_start=False)"
      ]
     },
     "execution_count": 105,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lr2 = linear_model.Lasso(alpha=0.05, random_state=1)\n",
    "lr2.fit(X_train_std, y_train_error)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 109,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.17846084266441412"
      ]
     },
     "execution_count": 109,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "metrics.mean_squared_error(y_train, lr.predict(X_train_std)) ** .5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 110,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.17845893538984411"
      ]
     },
     "execution_count": 110,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "metrics.mean_squared_error(y_train, lr.predict(X_train_std) + lr2.predict(X_train_std)) ** .5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 122,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "train rmse:  0.16015444122722466\n",
      "train r2:  0.9082817626656599\n",
      "test rmse:  0.24020018690351005\n",
      "test r2:  0.833494150500505\n"
     ]
    }
   ],
   "source": [
    "est = ensemble.GradientBoostingRegressor(max_depth=6, n_estimators=10, )\n",
    "est.fit(X_train_std, y_train)\n",
    "y_train_pred = est.predict(X_train_std)\n",
    "y_test_pred = est.predict(X_test_std)\n",
    "print(\"train rmse: \",  metrics.mean_squared_error(y_train, y_train_pred) ** 0.5)\n",
    "print(\"train r2: \",  metrics.r2_score(y_train, y_train_pred) ** 0.5)\n",
    "print(\"test rmse: \",  metrics.mean_squared_error(y_test, y_test_pred) ** 0.5)\n",
    "print(\"test r2: \",  metrics.r2_score(y_test, y_test_pred) ** 0.5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 123,
   "metadata": {},
   "outputs": [],
   "source": [
    "import xgboost as xgb"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 181,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "XGBRegressor(alpha=0.5, base_score=0.5, booster='gblinear', colsample_bylevel=1,\n",
       "             colsample_bynode=1, colsample_bytree=0.5, gamma=0,\n",
       "             importance_type='gain', learning_rate=0.1, max_delta_step=0,\n",
       "             max_depth=3, min_child_weight=1, missing=None, n_estimators=200,\n",
       "             n_jobs=1, nthread=None, objective='reg:squarederror',\n",
       "             random_state=0, reg_alpha=0, reg_lambda=0.3, scale_pos_weight=1,\n",
       "             seed=None, silent=None, subsample=1, verbosity=1)"
      ]
     },
     "execution_count": 181,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "est_xgb = xgb.XGBRegressor(\n",
    "                            booster= \"gblinear\",\n",
    "                            max_depth=3, \n",
    "                           n_estimators=200,\n",
    "                           learning_rate=0.1,\n",
    "                           objective=\"reg:squarederror\", \n",
    "                           colsample_bytree = 0.5,\n",
    "                            alpha = 0.5,\n",
    "                            reg_lambda = 0.3\n",
    "                          )\n",
    "est_xgb.fit(X_train_std, y_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 182,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "train rmse:  0.09590374316262254\n",
      "train r2:  0.9681109362863142\n",
      "test rmse:  0.1394151314931741\n",
      "test r2:  0.9471827914333071\n"
     ]
    }
   ],
   "source": [
    "y_train_pred = est_xgb.predict(X_train_std)\n",
    "y_test_pred = est_xgb.predict(X_test_std)\n",
    "print(\"train rmse: \",  metrics.mean_squared_error(y_train, y_train_pred) ** 0.5)\n",
    "print(\"train r2: \",  metrics.r2_score(y_train, y_train_pred) ** 0.5)\n",
    "print(\"test rmse: \",  metrics.mean_squared_error(y_test, y_test_pred) ** 0.5)\n",
    "print(\"test r2: \",  metrics.r2_score(y_test, y_test_pred) ** 0.5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 190,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Fitting 5 folds for each of 16 candidates, totalling 80 fits\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "[Parallel(n_jobs=8)]: Using backend LokyBackend with 8 concurrent workers.\n",
      "[Parallel(n_jobs=8)]: Done  34 tasks      | elapsed:   10.9s\n",
      "[Parallel(n_jobs=8)]: Done  80 out of  80 | elapsed:   30.5s finished\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "GridSearchCV(cv=5, error_score=nan,\n",
       "             estimator=XGBRegressor(alpha=0.5, base_score=0.5,\n",
       "                                    booster='gblinear', colsample_bylevel=1,\n",
       "                                    colsample_bynode=1, colsample_bytree=0.5,\n",
       "                                    gamma=0, importance_type='gain',\n",
       "                                    learning_rate=0.1, max_delta_step=0,\n",
       "                                    max_depth=3, min_child_weight=1,\n",
       "                                    missing=None, n_estimators=200, n_jobs=1,\n",
       "                                    nthread=None, objective='reg:squarederror',\n",
       "                                    random_state=0, reg_alpha=0, reg_lambda=0.3,\n",
       "                                    scale_pos_weight=1, seed=None, silent=None,\n",
       "                                    subsample=1, verbosity=1),\n",
       "             iid='deprecated', n_jobs=8,\n",
       "             param_grid={'booster': ['gblinear', 'gbtree'],\n",
       "                         'max_depth': array([2, 3, 4, 5, 6, 7, 8, 9])},\n",
       "             pre_dispatch='2*n_jobs', refit=True, return_train_score=False,\n",
       "             scoring=None, verbose=1)"
      ]
     },
     "execution_count": 190,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "param_grid = {\n",
    "    \"booster\": [\"gblinear\", \"gbtree\"],\n",
    "    \"max_depth\": np.arange(2, 10),\n",
    "    #\"learning_rate\": np.linspace(0.1, 0.9, 10),\n",
    "    #\"colsample_bytree\": np.linspace(0.3, 0.7, 10)\n",
    "}\n",
    "\n",
    "gsearch = model_selection.GridSearchCV(estimator= est_xgb, cv = 5, param_grid = param_grid,  verbose=1, n_jobs = 8)\n",
    "gsearch.fit(X_train_std, y_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 191,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'booster': 'gbtree', 'max_depth': 3}"
      ]
     },
     "execution_count": 191,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gsearch.best_params_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 192,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "train rmse:  0.059831818542215316\n",
      "train r2:  0.9877105772531495\n",
      "test rmse:  0.1370707566541226\n",
      "test r2:  0.9489915645502398\n"
     ]
    }
   ],
   "source": [
    "y_train_pred = gsearch.predict(X_train_std)\n",
    "y_test_pred = gsearch.predict(X_test_std)\n",
    "print(\"train rmse: \",  metrics.mean_squared_error(y_train, y_train_pred) ** 0.5)\n",
    "print(\"train r2: \",  metrics.r2_score(y_train, y_train_pred) ** 0.5)\n",
    "print(\"test rmse: \",  metrics.mean_squared_error(y_test, y_test_pred) ** 0.5)\n",
    "print(\"test r2: \",  metrics.r2_score(y_test, y_test_pred) ** 0.5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
